Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-stringify

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-stringify

remark plugin to compile Markdown

  • 9.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5M
decreased by-12.05%
Maintainers
2
Weekly downloads
 
Created

What is remark-stringify?

The remark-stringify package is a plugin for the remark ecosystem that allows you to serialize Markdown Abstract Syntax Trees (ASTs) into Markdown text. It is commonly used in conjunction with other remark plugins to process and transform Markdown content programmatically.

What are remark-stringify's main functionalities?

Basic Markdown Serialization

This feature allows you to convert a Markdown AST into a Markdown string. The example demonstrates how to serialize a simple AST representing a paragraph with the text 'Hello, world!'.

const remark = require('remark');
const stringify = require('remark-stringify');

const markdownAST = {
  type: 'root',
  children: [
    { type: 'paragraph', children: [{ type: 'text', value: 'Hello, world!' }] }
  ]
};

const markdownText = remark().use(stringify).stringify(markdownAST);
console.log(markdownText); // Outputs: 'Hello, world!\n'

Customizing Output

This feature allows you to customize the output format of the serialized Markdown. The example shows how to set options for bullet points and fenced code blocks.

const remark = require('remark');
const stringify = require('remark-stringify');

const markdownAST = {
  type: 'root',
  children: [
    { type: 'paragraph', children: [{ type: 'text', value: 'Hello, world!' }] }
  ]
};

const markdownText = remark()
  .use(stringify, { bullet: '*', fences: true })
  .stringify(markdownAST);
console.log(markdownText); // Outputs: 'Hello, world!\n'

Handling Complex ASTs

This feature demonstrates how to handle more complex ASTs, including headings, paragraphs, and lists. The example shows how to serialize an AST with multiple types of nodes.

const remark = require('remark');
const stringify = require('remark-stringify');

const markdownAST = {
  type: 'root',
  children: [
    { type: 'heading', depth: 1, children: [{ type: 'text', value: 'Title' }] },
    { type: 'paragraph', children: [{ type: 'text', value: 'This is a paragraph.' }] },
    { type: 'list', ordered: false, children: [
      { type: 'listItem', children: [{ type: 'paragraph', children: [{ type: 'text', value: 'Item 1' }] }] },
      { type: 'listItem', children: [{ type: 'paragraph', children: [{ type: 'text', value: 'Item 2' }] }] }
    ] }
  ]
};

const markdownText = remark().use(stringify).stringify(markdownAST);
console.log(markdownText); // Outputs: '# Title\n\nThis is a paragraph.\n\n* Item 1\n* Item 2\n'

Other packages similar to remark-stringify

Keywords

FAQs

Package last updated on 09 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc